// 3DModel.h

#ifndef __3DMODEL_H__
#define __3DMODEL_H__

#include <vector>

class CD3D9RenderUnit;
class CD3D9VertexDeclaration;
// unIndex
class C3DModel
{
public:
	struct tVertex
	{
		float vertex[3];
		//float normal[3];
		DWORD dwColor;
		float u, v;
	};

	struct tFrame
	{
		tVertex* pVertexData;
		tFrame()
		{
			pVertexData = NULL;
		}
		~tFrame()
		{
			if (pVertexData)
			{
				delete [] pVertexData;
				pVertexData = NULL;
			}
		}
	};

	struct tAnimation
	{
		int nStartFrame;
		int nEndFrame;
	};
	typedef std::map<std::string, tAnimation> CAnimationInfo;

protected:
	int m_nFrameAmount;
	int m_nFrameIndex;
	int m_nNumVertices;
	int m_nNumTriangles;
	tFrame* m_pFrameData;
	std::string m_strCurAnimation;
	CAnimationInfo m_mapAnimation;
	CD3D9RenderUnit* m_pRenderUnit;
	unsigned long m_ulLastFrameTime;
public:
	C3DModel();
	virtual ~C3DModel();

	// non-const method
	bool Create(const char* pszModelFile, CD3D9VertexDeclaration* pDecl);
	bool Load(const char* pszModelFile);
	void SetFrameIndex(int nFrame);
	void SetAnimation(const std::string& strName);

	// const method
	int GetVertexSize(void) const;
	int GetSubCount(void) const;
	int GetFrameAmount(void) const;
	int GetFrameIndex(void) const;
};

#endif